/*
 * DoubleProb.h
 *
 *  Created on: 05.12.2011
 *      Author: jan
 */

#ifndef DOUBLEPROB_H_
#define DOUBLEPROB_H_
#include <iostream>

namespace std {

#define MIN_PROBABILITY 0.01

class DoubleProb {
public:
	double val;
	double missed;
	double hits;

	DoubleProb(int hits, int missed):val(-1),missed(missed),hits(hits){}
	DoubleProb():val(-1),missed(0),hits(0) {
	}
	virtual ~DoubleProb(){
	}

	DoubleProb(const DoubleProb& p) {
		missed = p.missed;
		hits = p.hits;
		val = p.val;
	}

	DoubleProb& operator=(const DoubleProb &p) {
		missed = p.missed;
		hits = p.hits;
		val = p.val;
		return *this;
	}

	void hit(){
		hits++;
	}

	void miss(){
		missed++;
	}

	void operator++(){
		hit();
	}

	void operator--(){
		miss();
	}

	void operator++(int i){
		hit();
	}

	void operator--(int i){
		miss();
	}

	double getValue(){
		return ((missed+hits)>0)?value():-1;
	}

	bool operator==(double d){
		return value() == d;
	}

	bool operator>(double d){
		return value() > d;
	}
	bool operator<(double d) {
		return value() < d;
	}

	double value(){
		val = (hits/(hits+missed));
		val = (val < MIN_PROBABILITY) ? MIN_PROBABILITY : val;
		return val;
	}

	double operator()(){
		return value();
	}
};

} /* namespace std */
#endif /* DOUBLEPROB_H_ */
